package com.kun.lagou.commodity.controller;

import com.alibaba.fastjson.JSON;
import com.kun.lagou.commodity.api.dto.CommodityInfo;
import com.kun.lagou.commodity.service.CommodityService;
import com.kun.lagou.user.starter.annotation.LoginUserId;
import com.kun.lagou.user.starter.vo.UserVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class CommodityController {
    private final CommodityService commodityService;

    /**
     * 根据商品ID查询商品信息
     * @param id
     * @return
     */
    @GetMapping("/commodities/{id}")
    public CommodityInfo getById(@PathVariable("id") long id, @LoginUserId UserVo vo) {
        log.info("get user id: {}", JSON.toJSONString(vo));
        return commodityService.getById(id);
//        return CommodityInfo.builder().id(1).name("iphone 12 pro max").desc("iphone xxx").build();
    }
}
